package com.friend.chat.page.view.friend

import android.app.Activity
import android.content.Intent
import android.view.View
import com.bumptech.glide.Glide
import com.friend.chat.base.BaseActivity
import com.friend.chat.databinding.ActivityQrfreindBinding
import com.friend.chat.page.bean.UserBean
import com.friend.chat.page.vm.QrFriendViewModel
import com.friend.chat.utils.GlideUtils
import com.yzq.zxinglibrary.encode.CodeCreator

class QRFriendActivity : BaseActivity<ActivityQrfreindBinding, QrFriendViewModel>() {
    private lateinit var mUserBean: UserBean

    companion object {
        fun open(activity: Activity, userBean: UserBean) {
            val intent = Intent(activity, QRFriendActivity::class.java)
            intent.putExtra("userBean", userBean)
            activity.startActivity(intent)
        }
    }

    override fun yourViewModel(): QrFriendViewModel = QrFriendViewModel()

    override fun yourViewBing(): ActivityQrfreindBinding {
        return ActivityQrfreindBinding.inflate(layoutInflater)
    }

    override fun init() {
        mUserBean = intent.getSerializableExtra("userBean") as UserBean
        GlideUtils.loadRadiusImg1(mViewBinding.ivQrHeader, mUserBean.header, 4)
        mViewBinding.tvQrNickname.text = mUserBean.nickname
        mViewBinding.tvQrUsername.text = mUserBean.username
        mViewBinding.includeBar.barTitle.visibility = View.VISIBLE
        mViewBinding.includeBar.barTitle.text = "扫描二维码"
        mViewBinding.includeBar.barBack.setOnClickListener {
            finish()
        }

        Thread {
            val bitmapHeader =
                Glide.with(this).asBitmap().load(mUserBean.header).into(300, 300).get()
            runOnUiThread {

             //   val logo = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)
               val bitmap = CodeCreator.createQRCode( mUserBean.uid, 600, 600, bitmapHeader)
               // val bitmapMulti = addLogo(bitmapFirst, bitmapHeader, 0.2f)
                mViewBinding.ivQr.setImageBitmap(bitmap)
            }
        }.start()
    }
}